package com.slipper.bpmn.dealer.support;

import com.slipper.constants.FlowConstants;
import com.slipper.bpmn.BpmnEngine;
import com.slipper.bpmn.vo.BpmnVO;
import com.slipper.system.flow.bo.FlowInstBO;
import com.slipper.system.flow.bo.FlowInstNodeBO;
import com.slipper.system.flow.bo.FlowNodeBO;
import com.slipper.system.flow.service.FlowInstNodeService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import com.slipper.bpmn.dealer.INodeDealer;

/**
 * 分支节点处理器
 */
@Component
public class BranchNodeDealer implements INodeDealer {
    @Resource
    private FlowInstNodeService flowInstNodeService;
    @Resource
    private BpmnEngine bpmnEngine;
    
    @Override
    public String[] getTypes() {
        return new String[] { "20" };
    }

    @Override
    public FlowInstNodeBO doDeal(
            int dealCnt,
            boolean finished,
            FlowNodeBO flowNode,
            FlowInstBO flowInst,
            FlowInstNodeBO preInstNode,
            FlowInstNodeBO currInstNode,
            BpmnVO vo) {
        FlowInstNodeBO flowInstNode = new FlowInstNodeBO();
        flowInstNode.setInstId(flowInst.getId());
        flowInstNode.setPreInstNodeId(preInstNode.getId());
        flowInstNode.setLineId(flowNode.getInLineId());
        flowInstNode.setCurrFlowNodeId(flowNode.getId());
        flowInstNode.setDealManId(vo.getCurrEmpId());
        flowInstNode.setDealOrgId(vo.getCurrOrgId());
        flowInstNode.setStartTime(System.currentTimeMillis());
        flowInstNode.setEndTime(System.currentTimeMillis());
        flowInstNode.setUpdateTime(System.currentTimeMillis());
        flowInstNode.setCreateTime(System.currentTimeMillis());
        flowInstNode.setDealStatus(FlowConstants.FlowInstNode.DEAL_STATUS_FINISHED);
        flowInstNodeService.save(flowInstNode);
        bpmnEngine.next(dealCnt + 1, flowNode, flowInst, flowInstNode);
        return flowInstNode;
    }
}
